package cn.pn.project.controller;


import cn.pn.project.client.commodity.CommodityFeign;
import cn.pn.project.client.commodity.ShowtypeFeign;
import cn.pn.project.client.commodity.SkuFeign;
import cn.pn.project.client.commodity.TicketInfoFeign;
import cn.pn.project.client.schedule.CommoditySessionFeign;
import cn.pn.project.client.schedule.PlaceFeign;
import cn.pn.project.common.GetDate;
import cn.pn.project.common.Page;
import cn.pn.project.module.commodity.CommodityModule;
import cn.pn.project.pojo.commodity.Commodity;
import cn.pn.project.pojo.commodity.Sku;
import cn.pn.project.pojo.commodity.Ticketinginfo;
import cn.pn.project.pojo.schedule.Place;
import cn.pn.project.vo.CommodityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dis2/p")
public class ItemDisController2 {
    @Autowired
    private CommodityFeign commodityFeign;
    @Autowired
    private ShowtypeFeign showtypeFeign;
    @Autowired
    SkuFeign skuFeign;
    @Autowired
    CommoditySessionFeign commoditySessionFeign;
    @Autowired
    private TicketInfoFeign ticketInfoFeign;
    @Autowired
    PlaceFeign placeFeign;
    @PostMapping("/getPlace")
    public Place getPlace(@RequestParam("placeId") Integer placeId){
        Place place=null;
        try {
            place= placeFeign.getPlaceByPlaceId(placeId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return place;
    }
    /**
     * 绑定场次
     * @param commdityId
     * @return
     */
    @PostMapping("/getSkuByCommdityId")
    public  List<Sku> getSkuByCommdityId(@RequestParam("commdityId") Integer commdityId) throws Exception{
        System.out.println("进来了comtroller"+commdityId);
        List<Sku> skuLis= skuFeign.getSkuByCommdityId(commdityId);
        System.out.println(skuLis.size()+"sku长度");

        return skuLis;
    }

    /**
     * 转为中文
     * @param commdityId
     * @return
     */
    @PostMapping("/getSkuByCommdityId1")
    public  Object getSkuByCommdityId1(@RequestParam("commdityId") Integer commdityId){
        String sessionId="";
        System.out.println("进来了comtroller"+commdityId);
        List<Sku> skuList=null;
        try {
            skuList= skuFeign.getSkuByCommdityId(commdityId);
        }catch (Exception e){
            e.printStackTrace();
        }



        for (Sku sku:skuList){
            sessionId+=(sku.getSessionId()+",").toString();
        }
        Object object=null;
        String sessionIds=sessionId.substring(0,sessionId.length()-1);
        try {
            object=commoditySessionFeign.getCommoditysessionBySessionId(sessionIds);
        }catch (Exception e){
            e.printStackTrace();
        }
        return object;
    }

    /**
     * 绑定票档
     * @param commdityId
     * @param sessionId
     * @return
     */
    @PostMapping("/getSkuByCommdityIdAndsessionId")
    public  List<Sku> getSkuByCommdityIdAndsessionId(@RequestParam("commdityId") Integer commdityId,@RequestParam("sessionId") Integer sessionId) throws  Exception{
        List<Sku> skuList=skuFeign.getSkuByCommdityIdAndSessionId(commdityId,sessionId);
        return skuList;
    }

    /**
     * 查询商品信息
     * @param commodityId
     * @return
     */
    @PostMapping("/findCommodityAllMdfessage")
    public CommodityModule findCommodityAllMdfessage(@RequestParam("commodityId") Integer commodityId){
        System.out.println("-------------------------------------");
        CommodityModule commodityModule= commodityFeign.findCommodityAllMessage(commodityId);
        return commodityModule;
    }

    /**
     * 查询价格
     * @param commdityId
     * @param sessionId
     * @param ticketFileId
     * @return
     */
    @PostMapping("/getPrice1")
    public Sku getPrice1(@RequestParam("commdityId") Integer commdityId,@RequestParam("sessionId") Integer sessionId,@RequestParam("ticketFileId") Integer ticketFileId) throws  Exception{
        System.out.println(commdityId+"+++"+sessionId+"++"+ticketFileId+"controller");
        Sku sku= skuFeign.getPrice(commdityId,sessionId,ticketFileId);
        return sku;
    }

    /**
     * 根据id查名称  --场次
     * @param sessionIds
     * @return
     */
    @PostMapping("/getCommoditysessionBySessionId")
    public Object getCommoditysessionBySessionId(@RequestParam("sessionIds") String sessionIds){
        System.out.println("-------------------------------------"+sessionIds);
        Object object=null;
        try {
            object=commoditySessionFeign.getCommoditysessionBySessionId(sessionIds);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return object;
    }

    @RequestMapping(value = "/getTicketInfoByCommodityId", method = RequestMethod.POST)
    Ticketinginfo getTicketInfoByCommodityId(@RequestParam("commodityId") Integer commodityId){
        return ticketInfoFeign.getTicketInfoByCommodityId(commodityId);
    }

}
